package com.vol.controller.sys;

import com.vol.entity.Result;
import com.vol.entity.SysDepartment;
import com.vol.entity.UserInfo;
import com.vol.entity.pager.PageParams;
import com.vol.entity.pager.ResultPager;
import com.vol.requestparams.UpdateSubmitParams;
import com.vol.sys.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;

@RestController
@RequestMapping("api/Sys_Department")
public class DepartmentController {
    @Autowired
    private DepartmentService departmentService;
    @PostMapping("getPageData")
    public ResultPager<SysDepartment> getPageData(@RequestBody PageParams pageParams){
        ResultPager<SysDepartment> result = departmentService.getPageData(pageParams);
        return result;
    }

    @PostMapping("update")
    public Result update(@RequestBody UpdateSubmitParams<SysDepartment> params){
        SysDepartment sysDepartment = params.mainData;
        departmentService.saveOrUpdate(sysDepartment);
        return Result.ok(sysDepartment,311,"保存成功！");
    }

    @RequestMapping("Add")
    public Result Add(@RequestBody UpdateSubmitParams<SysDepartment> params){
        SysDepartment sysDepartment = params.mainData;
        departmentService.saveOrUpdate(sysDepartment);
        return Result.ok(sysDepartment,311,"保存成功！");
    }

    @PostMapping("del")
    public Result del(@RequestBody ArrayList<String> ids){
        departmentService.del(ids);
        return Result.ok(null,317,"删除成功！");
    }
}
